#include <interpreter_pattern.h>

TerminalExpression::TerminalExpression(string data)
{
    this->data = data;
}

bool TerminalExpression::interpret(string context)
{
    if (context.find(this->data) != string::npos)
    {
        return true;
    }
    return false;
}

OrExpression::OrExpression(Expression* expr1, Expression* expr2)
{
    this->expr1 = expr1;
    this->expr2 = expr2;
}

OrExpression::~OrExpression()
{
    delete this->expr1;
    delete this->expr2;
}

bool OrExpression::interpret(string context)
{
    return this->expr1->interpret(context) || this->expr2->interpret(context);
}

AndExpression::AndExpression(Expression* expr1, Expression* expr2)
{
    this->expr1 = expr1;
    this->expr2 = expr2;
}

AndExpression::~AndExpression()
{
    delete this->expr1;
    delete this->expr2;
}

bool AndExpression::interpret(string context)
{
    return this->expr1->interpret(context) && this->expr2->interpret(context);
}
